<template>
  <div>
        <el-form
      :model="formData"
      inline
      style="display: flex; justify-content: flex-end; margin-top: 10px"
    >
      <el-form-item prop="userId">
        <el-input
          v-model="formData.userId"
          placeholder="请输入用户id"
        ></el-input>
      </el-form-item>

      <el-form-item prop="name">
        <el-input
          v-model="formData.name"
          placeholder="请输入收货人名称"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button @click="getAddress" type="primary" icon="el-icon-search">查找</el-button>
      </el-form-item>
    </el-form>




    <el-table v-loading="tableListLoading" :data="tableData" border >
     <el-table-column align="center" label="收获地址id" prop="id"></el-table-column>
     <el-table-column align="center" label="用户ID" prop="userId"></el-table-column>
     <el-table-column align="center" label="收获人名称" prop="name"></el-table-column>
     <el-table-column align="center" label="手机号码" prop="tel"></el-table-column>
     <el-table-column align="center" label="区域地址" prop="province+city+country"></el-table-column>
     <el-table-column align="center" label="详细地址" prop='addressDetail'></el-table-column>
     <el-table-column align="center" label="默认" prop='isDefault'></el-table-column>
    </el-table>

     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.page"
      :page-sizes="[1, 20, 30, 50, 100]"
      :page-size="pageInfo.limit"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
    >
    </el-pagination>
  </div>
</template>
  
<script>
import axios from 'axios'
export default {
  name: 'shippingAddress',
  componentTitle: '收货地址',
  data () {
    return {
      tableListLoading:false,
       pageInfo: {
        page: 1,
        limit: 1,
        total: 0,
      },
      tableData:[],
      formData:{
            name:'',
            userId:''
      }
    }
  },
  mounted(){
   this.getAddress()
  },
  methods:{
    getAddress(){
      this.tableListLoading=true

      axios({
        url:'http://192.168.200.251:8888/admin/address/list',
        method:'get',
        params:{
            page: this.pageInfo.page,
            limit: this.pageInfo.limit,
           ...this.formData
        },
           headers: {
          "shopping-admin-token": sessionStorage.getItem(
            "shopping-admin-token"
          ),
        },

      }).then(res=>{
        this.tableListLoading=false

        this.tableData=res.data.data.list
        this.pageInfo.total=res.data.data.total

        
      })
    },
        handleSizeChange(value) {
      this.pageInfo.limit = value;

      this.getAddress();
    },
    // 当前页码的切换
    handleCurrentChange(value) {
      this.pageInfo.page = value;

      this.getAddress();
    },
  }
}
</script>


